

#include "httpcommon.h"
#include "HttpMsg.h"


//
// Function definitions of CHttpMsg class
//
CHttpMsg::CHttpMsg():
mpMsgHeader(NULL), mpMsgBody(NULL),
mHeaderLen(0), mBodyLen(0)
{}

CHttpMsg::~CHttpMsg()
{
	cleanupMsg();
}

void CHttpMsg::cleanupMsg()
{
	if(mpMsgHeader != NULL)
		delete mpMsgHeader;
	if(mpMsgBody != NULL)
		delete mpMsgBody;

	mpMsgHeader = NULL;
	mpMsgBody = NULL;
	mHeaderLen = 0;
	mBodyLen = 0;
}


//
// Function definitions of CReqHttpMsg class
//
CReqHttpMsg::CReqHttpMsg()
{}

CReqHttpMsg::~CReqHttpMsg()
{}

void CReqHttpMsg::cleanupMsg()
{
	CHttpMsg::cleanupMsg();
}

CReqHttpMsg& CReqHttpMsg::operator =(const CReqHttpMsg &reqmsg)
{
	cleanupMsg();
	mHeaderLen = reqmsg.mHeaderLen;
	mBodyLen = reqmsg.mBodyLen;

	mpMsgHeader = new char[mHeaderLen];
	mpMsgBody = new char[mBodyLen];

	// if a process of asignment has failed, it has to take care of by exception handler.
	if(mpMsgHeader == NULL || mpMsgBody == NULL)
		return *this;

	memcpy(mpMsgHeader, reqmsg.mpMsgHeader, mHeaderLen);
	memcpy(mpMsgBody, reqmsg.mpMsgBody, mBodyLen);

	return *this;
}

//
// Function definitions of CResHttpMsg class
//
CResHttpMsg::CResHttpMsg()
{}

CResHttpMsg::~CResHttpMsg()
{}

void CResHttpMsg::cleanupMsg()
{
	CHttpMsg::cleanupMsg();
}

CResHttpMsg& CResHttpMsg::operator =(const CResHttpMsg &resmsg)
{
	cleanupMsg();
	mHeaderLen = resmsg.mHeaderLen;
	mBodyLen = resmsg.mBodyLen;

	mpMsgHeader = new char[mHeaderLen];
	mpMsgBody = new char[mBodyLen];

	// if a process of asignment has failed, it has to take care of by exception handler.
	if(mpMsgHeader == NULL || mpMsgBody == NULL)
		return *this;

	memcpy(mpMsgHeader, resmsg.mpMsgHeader, mHeaderLen);
	memcpy(mpMsgBody, resmsg.mpMsgBody, mBodyLen);

	return *this;
}
